//
// Created by 11401 on 25-7-14.
//

#ifndef BSP_ATS_H
#define BSP_ATS_H


#include "main.h"

typedef  struct {
    uint8_t *tx_buffer;
    uint8_t *rx_buffer;
    UART_HandleTypeDef *huart;
    bool flag;
}BSP_ATS522_T;

extern uint8_t ats522_rx_bueff[32];
extern uint8_t ats522_tx_bueff[32];
extern BSP_ATS522_T ats522;
extern osMessageQueueId_t ic_rx_packHandle;
extern osSemaphoreId_t IC_UARTHandle;
void bsp_ats522_init(UART_HandleTypeDef *huart);
//写数据
 bool bsp_ats522_write(uint8_t *data,uint8_t size);
//
uint8_t bsp_ats522_read(uint8_t *rx_data,uint16_t size);
//计算校验和
uint8_t bsp_ats522_rcc(uint8_t *data,uint8_t size);
//空闲中断读数据
void bsp_ats522_callback(UART_HandleTypeDef *huart);
//请求
bool bsp_ast522_Request(void);
//防碰撞
bool bsp_ast522_PiccAnticoll(void);
//选择
bool bsp_ats522_PiccSelect(uint8_t id_1,uint8_t id_2,uint8_t id_3,uint8_t id_4);
//暂停
bool bsp_ast522_PiccHalt(void);
//验证密钥
bool bsp_ats522_PiccAuthKey(uint8_t AB,
                            uint8_t id_1,uint8_t id_2,uint8_t id_3,uint8_t id_4,
                            uint8_t key[6],
                            uint8_t Card_block);
//读数据
bool bsp_ats522_Read(uint8_t Card_block);
//读数据
bool bsp_ats522_Write_data(uint8_t Card_block,uint8_t data[16]);
//块读

bool bsp_ats522_block_Read(uint8_t begen,
                            uint8_t block,
                            uint8_t key_class,
                            uint8_t key[6]);
//块写
bool bsp_ats522_block_Wirte(uint8_t begen,
                            uint8_t block,
                            uint8_t key_class,
                            uint8_t key[6],
                            uint8_t data[16]);

#endif //BSP_ATS_H
